﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
 }
<div class="layui-fluid" style="padding:0 0px">
    <div class="layui-row layui-col-space5">
        <div class="layui-col-md4 layui-col-xs5">
            <div class="layui-card" style="padding: 5px;">
                <fieldset class="table-search-fieldset" style="border:1px solid #e6e6e6">
                    <legend>工序</legend>
                    <form class="layui-form layui-form-pane" action="">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <input type="text" id="txt_keyword" name="txt_keyword" autocomplete="off" class="layui-input" placeholder="">
                            </div>
                            <div class="layui-inline">
                                <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon">&#xe615;</i> 搜 索</button>
                            </div>
                        </div>
                    </form>
                </fieldset>
                <script type="text/html" id="toolbarDemo">
                    <div class="layui-btn-container" id="toolbar">
                        <button id="NF-add" name="NF-add" authorize class="layui-btn layui-btn-sm data-add-btn" lay-event="add"><i class="layui-icon">&#xe654;</i>新增</button>
                        <button id="NF-edit" name="NF-edit" authorize class="layui-btn layui-btn-sm layui-btn-warm data-edit-btn layui-hide" lay-event="edit"><i class="layui-icon">&#xe642;</i>修改</button>
                        <button id="NF-delete" name="NF-delete" authorize class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn layui-hide" lay-event="delete"> <i class="layui-icon">&#xe640;</i>删除</button>
                        <button id="NF-details" name="NF-details" authorize class="layui-btn layui-btn-sm layui-btn-normal data-info-btn layui-hide" lay-event="details"> <i class="layui-icon">&#xe60b;</i>查看</button>
                    </div>
                </script>
                <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
            </div>
        </div>
        <div class="layui-col-md8 layui-col-xs7">
            <div class="layui-card" style="padding: 5px;">
                <fieldset class="table-search-fieldset" style="border:1px solid #e6e6e6">
                    <legend>绑定设备</legend>
                    <form class="layui-form layui-form-pane" action="">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <input type="text" id="temp_txt_keyword" name="temp_txt_keyword" autocomplete="off" class="layui-input" placeholder="">
                            </div>
                            <div class="layui-inline">
                                <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="temp-search-btn"><i class="layui-icon">&#xe615;</i> 搜 索</button>
                            </div>
                        </div>
                    </form>
                </fieldset>
                <script type="text/html" id="toolbarTemp">
                    <div class="layui-btn-container" id="tool">
                        <button id="TF-add" name="TF-add" authorize class="layui-btn layui-btn-sm data-add-btn" lay-event="add"><i class="layui-icon">&#xe654;</i>新增</button>
                        <button id="TF-delete" name="TF-delete" authorize class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn layui-hide" lay-event="delete"> <i class="layui-icon">&#xe640;</i>删除</button>
                    </div>
                </script>
                <table class="layui-hide" id="currentTable" lay-filter="currentTable"></table>
            </div>
        </div>
    </div>
</div>
 <script>
     layui.use(['jquery', 'form','table','commonTable', 'common','optimizeSelectOption'], function () {
         var $ = layui.jquery,
             form = layui.form,
             table = layui.table,commonTable = layui.commonTable
             common = layui.common;
         var entity;
         var itemId;
         //权限控制(js是值传递)
         toolbarDemo.innerHTML = common.authorizeButtonNew(toolbarDemo.innerHTML);
         toolbarTemp.innerHTML = common.authorizeButtonNew(toolbarTemp.innerHTML);
         commonTable.rendertable({
             elem: '#currentTableId',
             id: 'currentTableId',
             url: '/ProcessManage/ProcessFlow/GetGridJson',
             search: false,
             defaultToolbar: [],
             height: 'full-130',
             cols: [[
                 { field: 'F_ProcessFlowName', title: '工序名称', width: 120, sort: true, filter: true },
                 { field: 'F_Description', title: '工序说明', minWidth: 105, sort: true, filter: true },
                 {
                     field: 'F_EnabledMark', title: '状态', width: 80, sort: true, filter: true,
                     templet: function (d) {
                         if (d.F_EnabledMark == true) {
                             return "<span class='layui-btn layui-btn-normal layui-btn-xs'>有效</span>";
                         } else {
                             return "<span class='layui-btn layui-btn-warm layui-btn-xs'>无效</span>";
                         }
                     }
                 },
                 {
                     field: 'F_CreatorTime', title: '创建时间', width: 160, sort: true, filter: { type: 'date[yyyy/MM/dd HH:mm:ss]' }
                 },

             ]]
         });
         commonTable.rendertable({
             elem: '#currentTable',
             id: 'currentTable',
             toolbar: '#toolbarTemp',//工具栏
             data: [],
             search: false,
             limit: 9999,//每页数据 默认
             page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                 layout: ['count'] //自定义分页布局
                 , first: false //不显示首页
                 , last: false //不显示尾页
             },
             defaultToolbar: [],
             height: 'full-130',
             cols: [[
                 { type: "checkbox", width: 50 },
                 {
                     field: 'F_EqpType', title: '设备类型', width: 120, sort: true, filter: true,
                     templet: function (d) {
                         return top.clients.dataItems["Mes_EqpType"][d.F_EqpType] == null ? "" : top.clients.dataItems["Mes_EqpType"][d.F_EqpType];
                     }
                 },
                 {
                     field: 'F_EqpUse', title: '设备用途', width: 120, sort: true, filter: true,
                     templet: function (d) {
                         return top.clients.dataItems["Mes_EqpUse"][d.F_EqpUse] == null ? "" : top.clients.dataItems["Mes_EqpUse"][d.F_EqpUse];
                     }
                 },
                 { field: 'F_EqpName', title: '设备名称', width: 120, sort: true, filter: true },

                 {
                     field: 'F_EqpState', title: '设备状态', width: 120, sort: true, filter: true,
                     templet: function (d) {
                         return top.clients.dataItems["Mes_EqpState"][d.F_EqpState] == null ? "" : top.clients.dataItems["Mes_EqpState"][d.F_EqpState];
                     }
                 },
                 {
                     field: 'F_EnabledMark', title: '状态', width: 80, sort: true, filter: true,
                     templet: function (d) {
                         if (d.F_EnabledMark == true) {
                             return "<span class='layui-btn layui-btn-normal layui-btn-xs'>有效</span>";
                         } else {
                             return "<span class='layui-btn layui-btn-warm layui-btn-xs'>无效</span>";
                         }
                     }
                 },
                 { field: 'F_Description', title: '设备描述', minWidth: 120, sort: true, filter: true },

             ]]
         });
         // 监听搜索操作
         form.on('submit(data-search-btn)', function (data) {
             //执行搜索重载
             commonTable.reloadtable({
                 elem: 'currentTableId',
                 curr: 1,
                 where: { keyword: data.field.txt_keyword}
             });
             entity = null;
             itemId = null;
             return false;
         });
         // 监听搜索操作
         form.on('submit(temp-search-btn)', function (data) {
             //执行搜索重载
             common.ajax({
                 url: '/ProcessManage/ProcessFlow/GetEqpGridJson',
                 dataType: 'json',
                 data: { itemId: itemId, keyword: data.field.temp_txt_keyword },
                 async: false,
                 success: function (data) {
                     if (data.data) {
                         table.reload('currentTable', {
                             data: data.data
                         });
                     }
                 }
             });
             item = null;
             return false;
         });
         wcLoading.close();
         table.on('row(currentTableFilter)', function (obj) {
             obj.tr.addClass("layui-table-click").siblings().removeClass("layui-table-click");
             entity = obj;
             itemId = obj.data.F_Id;
             $('[name="NF-edit"]').removeClass("layui-hide");
             $('[name="NF-details"]').removeClass("layui-hide");
             $('[name="NF-delete"]').removeClass("layui-hide");
             $("#temp_txt_keyword").val('');
             $('button[lay-filter="temp-search-btn"]').click();//按钮刷新
         })
         //行点击事件监听，控制按钮显示
         var moreList = ["TF-delete"];//选择多条显示
         commonTable.tableRowClick("checkbox", "currentTable", "currentTable", null, moreList);
         //toolbar监听事件
         table.on('toolbar(currentTableFilter)', function (obj) { 
             if (obj.event === 'add') {  // 监听添加操作
                 common.modalOpen({
                     title: "添加工序",
                     url: "/ProcessManage/ProcessFlow/Form",
                     width: "400px",
                     height: "400px",
                 });
             } 
             else if (obj.event === 'delete') {
                 if (entity == null) {
                     common.modalMsg("未选中数据", "warning");
                     return false;
                 }
                 common.deleteForm({
                     url: "/ProcessManage/ProcessFlow/DeleteForm",
                     param: { keyValue: entity.data.F_Id },
                     success: function () {
                         common.reload('data-search-btn');
                         entity = null;
                   }
               });
           }
           else if (obj.event === 'edit') {
               if (entity == null) {
                   common.modalMsg("未选中数据", "warning");
                   return false;
               }
               common.modalOpen({
                  title: "编辑工序",
                   url: "/ProcessManage/ProcessFlow/Form?keyValue=" + entity.data.F_Id,
                   width: "400px",
                   height: "400px",
               });
           }
           else if (obj.event === 'details') {
               if (entity == null) {
                   common.modalMsg("未选中数据", "warning");
                   return false;
               }
               common.modalOpen({
                  title: "查看工序",
                   url: "/ProcessManage/ProcessFlow/Details?keyValue=" + entity.data.F_Id,
                   width: "400px",
                   height: "400px",
                  btn: []
               });
           }
           return false;
         });
         //tool监听事件
         table.on('toolbar(currentTable)', function (obj) {
             var data = table.checkStatus('currentTable').data;
             if (obj.event === 'add') {  // 监听添加操作
                 if (!itemId) {
                     return false;
                 }
                 common.modalOpen({
                     title: "添加设备",
                     url: "/ProcessManage/ProcessFlow/EqpForm?itemId=" + itemId,
                     width: "600px",
                     height: "600px",
                 });
             }
             else if (obj.event === 'delete') {
                 if (data.length == 0) {
                     common.modalMsg("未选中数据", "warning");
                     return false;
                 }
                 var ids = [];
                 for (var i = 0; i < data.length; i++) {
                     ids.push(data[i].F_Id);
                 }
                 common.deleteForm({
                     url: "/ProcessManage/ProcessFlow/DeleteEqpForm",
                     param: { keyValue: ids.join(',') },
                     success: function () {
                         common.reload('temp-search-btn');
                         entity = null;
                     }
                 });
             }
             return false;
         });
   });
</script>
